<template>
  <div ref="chartRef" :style="{ height, width }"></div>
</template>
<script lang="ts" setup>
  import {onMounted, ref, Ref} from 'vue';
  import {useECharts} from '/@/hooks/web/useECharts';

  const props = defineProps({
    width: {
      type: String as PropType<string>,
      default: '100%',
    },
    height: {
      type: String as PropType<string>,
      default: '280px',
    },
    monthItem: {
      type: Object,
      default: null,
    },
  });

  const chartRef = ref<HTMLDivElement | null>(null);
  const {setOptions} = useECharts(chartRef as Ref<HTMLDivElement>);

  onMounted(() => {
    setOptions({
      tooltip: {
        trigger: 'axis',
        axisPointer: {
          lineStyle: {
            width: 1,
            color: '#019680',
          },
        },
      },
      grid: {left: '1%', right: '1%', top: '2  %', bottom: 0, containLabel: true},
      xAxis: {
        type: 'category',
        data: [
          '1月',
          '2月',
          '3月',
          '4月',
          '5月',
          '6月',
          '7月',
          '8月',
          '9月',
          '10月',
          '11月',
          '12月',
        ],
      },
      yAxis: {
        type: 'value',
        max: 20000,
        splitNumber: 4,
      },
      series: [
        {
          data: props.monthItem as any,
          type: 'bar',
          barMaxWidth: 80,
        },
      ],
    });
  });

</script>
